package com.project.common.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStream;

/**
* @Description:   JSON文件解析类
* @Author:         wangzhiqiang
* @CreateDate:     2019/1/18 11:35
* @Version:        1.0
*/
public class JsonFileAnalysis {

    /**
     * 读取文件
     * @param path
     * @return
     */

    public static JSONObject ReadJson(String path){
        ClassPathResource resource = new ClassPathResource(path);
        InputStream stream = null;

        String reader = null;
        try {
            stream = resource.getInputStream();

            byte[] bytes = new byte[0];
            bytes = new byte[stream.available()];
            stream.read(bytes);
            reader = new String(bytes);
        } catch (IOException e) {
            e.printStackTrace();
        }
        JSONObject jsonObject = JSON.parseObject(reader);

        return jsonObject;
    }

}
